package com.itheima.stock.service.impl;

import com.itheima.stock.mapper.StockOuterMarketIndexInfoMapper;
import com.itheima.stock.pojo.domain.*;
import com.itheima.stock.pojo.vo.StockInfoConfig;
import com.itheima.stock.service.StockerOutService;
import com.itheima.stock.utils.DateTimeUtil;
import com.itheima.stock.vo.resp.R;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@ApiModel
@Service
public class StockerOutServiceImpl implements StockerOutService {
    @ApiModelProperty(hidden = true)
    @Autowired
    private StockOuterMarketIndexInfoMapper stockOuterMarketIndexInfoMapper;
    @ApiModelProperty(hidden = true)
    @Autowired
    private StockInfoConfig stockInfoConfig;
    /**
     * 大盘数据获取
     * @return
     */
    @Override
    public R<List> getOuterStockIndex() {
        //大盘编码
        List<String> mCodes = stockInfoConfig.getOuter();
        //1.获取当前时间，精确到分钟
        DateTime curDate = DateTimeUtil.getLastDate4Stock(DateTime.now()).toDateTime();
        Date curDateTime = curDate.toDate();
        //(1).暂时无采集，使用假数据时间
            curDateTime = DateTime.parse("2022-01-01 10:57:00", DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss")).toDate();
        List<OuterMarkDomain> outInfos=stockOuterMarketIndexInfoMapper.getOuterByTime(curDateTime,mCodes);
        return R.ok(outInfos);
    }

    /**
     * like查询根据code
     * @param
     * @return
     */
    @Override
    public R<List> getStockLikeCode(Integer searchStr) {
        //1.获取当前时间，精确到分钟
        DateTime curDate = DateTimeUtil.getLastDate4Stock(DateTime.now()).toDateTime();
        Date curDateTime = curDate.toDate();
        //(1).暂时无采集，使用假数据时间
        curDateTime = DateTime.parse("2022-01-05 09:47:00", DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss")).toDate();
      List<LikesMarkDomain> likes=  stockOuterMarketIndexInfoMapper.getStockLikeCode(curDateTime,searchStr);

        return R.ok(likes);
    }

    /**
     * 根据code获取详情
     * @param code
     * @return
     */
    @Override
    public R<DescribeDomain> getDescribeByCode(String code) {
        DescribeDomain describeDomain= stockOuterMarketIndexInfoMapper.getStockByCode(code);

        return R.ok(describeDomain);
    }

    /**
     * 周k线-bycode
     * @param stockCode
     * @return
     */
    @Override
    public R<List> getScreenWeekkline(String stockCode) {
        //1.获取当前时间，精确到分钟
        DateTime curDate = DateTimeUtil.getLastDate4Stock(DateTime.now()).toDateTime();
        Date curDateTime = curDate.toDate();
        //(1).暂时无采集，使用假数据时间
        curDateTime = DateTime.parse("2024-07-12 15:00:00", DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss")).toDate();
        List<StockweekklineDomain> stockWeekLine= stockOuterMarketIndexInfoMapper.getScreenWeekkline(curDateTime,stockCode);

        return R.ok(stockWeekLine);
    }

    /**
     * 个股最新分时行情数据接口分析
     * @param stockCode
     * @return
     */
    @Override
    public R<StockRt1> getScreenSecondDetail(String stockCode) {
        //1.获取当前时间，精确到分钟
        DateTime curDate = DateTimeUtil.getLastDate4Stock(DateTime.now()).toDateTime();
        Date curDateTime = curDate.toDate();
        //(1).暂时无采集，使用假数据时间
        curDateTime = DateTime.parse("2022-01-05 09:47:00", DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss")).toDate();
     StockRt1 stockRt1 =  stockOuterMarketIndexInfoMapper.getScreenSecondDetailInfo(stockCode,curDateTime);
        return R.ok(stockRt1);
    }

    /**
     * 个股查询最新交易流水
     * @param stockCode
     * @return
     */
    @Override
    public R<List<StockAnInfoDomain>> getScreenSecond(String stockCode) {
        //1.获取当前时间，精确到分钟
        DateTime curDate = DateTimeUtil.getLastDate4Stock(DateTime.now());
                curDate = DateTime.parse("2022-07-13 14:49:00", DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"));

        Date curDateTime = curDate.toDate();
        //(1).暂时无采集，使用假数据时间


        Date openDate = DateTimeUtil.getOpenDate(curDate).toDate();
      List<StockAnInfoDomain>  stockAnInfoDomain = stockOuterMarketIndexInfoMapper.getScreenSecond(stockCode,openDate,curDateTime);
        return R.ok(stockAnInfoDomain);
    }
}
